/** 
 * @fileoverview 
 * layout.grid package
 * 
 * 
 * @author Kelemen Viktor kelemen.viktor@gmail.com
 * @version 0.1
 * 
 */

YAHOO.namespace('layout.grid');

	/**
	 * Makes a grid from the elements
	 * 
	 * @param {Array} elements
	 * @param {Object} config
	 */
	YAHOO.layout.grid.makeGrid = function(elements, config) {	

		var stepx = config.stepx;
		var stepy = config.stepy;
		var cx = config.cx != null ? config.cx : 0;
		var cy = config.cy != null ? config.cy : 0;
		
		var gridx = Math.floor(Math.sqrt(elements.length));
		var posx = 0, posy = 0;
		dojo.forEach(elements, function(e,i)	{
			
			if (posx==gridx)	{
				posx=0;
				posy++;
			}
			var x = posx*stepx+cx;
			var y = posy*stepy+cy;
			e.setTransform({ dx: x, dy: y});
			posx++;
		});
		
    }     